package com.fuxue.controller.server;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fuxue.dto.HelpTunDTO;
import com.fuxue.dto.QuestionDetialsDTO;
import com.fuxue.dto.QuestionPageShowDTO;
import com.fuxue.dto.WriteQuestionDTO;
import com.fuxue.result.PageResult;
import com.fuxue.result.Result;
import com.fuxue.service.QuestionService;
import com.fuxue.vo.QuestionAndColumVO;
import com.fuxue.vo.QuestionDetialsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController("serverQuestionController")
@RequestMapping("/users/server/question")
@Slf4j
@Api(tags = "服务者问题相关接口")
public class QuestionController {
       @Autowired
       private QuestionService questionService;
/*
首页问题展示
 */
       @GetMapping("/show")
       @ApiOperation("首页显示问题")
       private Result<List<QuestionAndColumVO>> questionAndColumVO(@RequestParam Integer id)
       {
           log.info("服务者id,{}",id);
              List<QuestionAndColumVO> questionList = new ArrayList<QuestionAndColumVO>();
              questionList = questionService.getSomeQuestion(id);
              log.info("结果",questionList);
              return Result.success(questionList);
       }

    @PostMapping("/notFinish")
    @CrossOrigin
    @ApiOperation("查询未完成问题")
    private Result<PageResult> QaShow(@RequestBody QuestionPageShowDTO questionPageShowDTO)
    {
        log.info("问题分页查询，参数为：{}",questionPageShowDTO);
        System.out.println(questionPageShowDTO.getFiled());
        PageResult pageResult = questionService.pageQuery(questionPageShowDTO);
        return Result.success(pageResult);
    }
    @GetMapping("/Finished")
    @CrossOrigin
    @ApiOperation("查询已完成问题")
    private Result<PageResult> QaFinishShow( QuestionPageShowDTO questionPageShowDTO)
    {
        log.info("问题分页查询，参数为：{}",questionPageShowDTO);
        PageResult pageResult = questionService.pageFinishedQuery(questionPageShowDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/detials")
    @ApiOperation("展示问题细节")
    private Result<QuestionDetialsVO>QaDetials(Integer id)
    {
        log.info("查询问题详情，参数为：{}",id);
        QuestionDetialsVO questionDetialsVO = new QuestionDetialsVO();
        questionDetialsVO = questionService.getQuestionDetials(id);

        return Result.success(questionDetialsVO);
    }

    @PostMapping("/write")
    @ApiOperation("写回答")
    private Result Insert(@RequestBody WriteQuestionDTO writeQuestionDTO)
    {
        log.info("写回答,参数为：{}",writeQuestionDTO);
        questionService.setAnswer(writeQuestionDTO);

        return Result.success();
    }
    @PostMapping("/money")
    private Result GiveUp(@RequestBody HelpTunDTO helpTunDTO) throws JsonProcessingException {
        log.info("发布悬赏，参数为，{}",helpTunDTO);
        questionService.giveUp(helpTunDTO);
        return Result.success();
    }


}
